﻿<?php
class IndexAction extends GlobalAction
{
   
    public function index()
    {
		Load('extend');	
                self::change_pic();
		//推荐公司
		$list_rec_company = parent::rec_company();
		$this->assign('list_rec_company',$list_rec_company);
		//平台帮助
		$list_rec_help = parent::rec_help();
		$this->assign('list_rec_help',$list_rec_help);
		//招聘
		$list_new_zhaopin = parent::new_zhaopin();
		$this->assign('list_new_zhaopin',$list_new_zhaopin);
		//人物博客
		$list_rec_person = parent::rec_person();
		$this->assign('list_rec_person',$list_rec_person);
		
		//推荐产品
		$list_rec_product = self:: list_poduct('rec');
		$this->assign('list_rec_product',$list_rec_product);
		//最新发布
		$list_new_product = self:: list_poduct('new',6);
		$this->assign('list_new_product',$list_new_product);
		//新闻
		self::list_news();
		//最新加盟公司
		$list_new_company = self::new_company();
		$this->assign('list_new_company',$list_new_company);

        $this->display();
    }

//首页幻灯片
public function change_pic(){
		
	$index_pic = M('company_news')->where("pic<>''")->limit(5)->order('add_date desc')->select();
	$total_url = '';
	foreach($index_pic as $k=>$v)
	{
	$total_url = $total_url . $v['pic'] . "|";
	$total_link= $total_link . trim("show_xinwen/".$v['company_id'].'-'.$v['news_id'].'html'). "|";
	$total_title= $total_title . $v['title']."|";
	}
	if( $total_url != '')
	{
	$total_url =  substr($total_url,0,strlen($total_url)-1);
	$total_link =  substr($total_link,0,strlen($total_link)-1);
	$total_title =  substr($total_title ,0,strlen($total_title)-1);
	}
	$this->assign('total_url',$total_url);
	$this->assign('total_link',$total_link);
	$this->assign('total_title',$total_title);
	}
//产品相关列表
function list_poduct($where,$num=8){
	     if($where == 'rec')
		 {
		$list_rec_product = M('products')->where('t_tuijian=1')->limit($num)->order('id desc')->select();
		 }
		 elseif($where == 'new')
		{
		$list_rec_product = M('products')->limit($num)->order('id desc')->select();	
		}
		
		foreach($list_rec_product as $k=>$v){
		$list_rec_product[$k]['company_name'] = parent::_get_field('company','id='.$v['company_id'],'company_name');
		if($v['buy_url'] != '')
		{
		$list_rec_product[$k]['url'] =$v['buy_url'];
		}
		else
		{
		$list_rec_product[$k]['url'] ="show_product/".$v['company_id'].'-'.$v['id'].'.html';
		}
		}
		return $list_rec_product;
	}
//新闻列表
function list_news(){
	$list_news = M('company_news')->limit(10)->order('add_date desc')->select();
		foreach($list_news as $k=>$v)
		{
		$list_news[$k]['new_type'] = C('NEWS_TYPE.'.$v['news_class']);
		if((time() - strtotime($v['add_date'])) <= 3*24*3600) 
		{
		$list_news[$k]['is_new'] = true;
		}
		else
		{
		$list_news[$k]['is_new'] = false;
		}
		}
		$this->assign('list_news',$list_news);
	}
//最新加盟公司
function new_company($num=4){
		$list_new_company = M('company')->limit($num)->order('id desc')->select();
		return $list_new_company;
		}


	

}
?>